package com.easysoft.framework.action;
import com.easysoft.framework.annotation.logs.SystemControllerLog;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.chat.model.SysChatcontent;
import com.easysoft.framework.chat.model.SysChatcontentQuery;
import com.easysoft.framework.chat.model.SysChatcontentView;
import com.easysoft.framework.chat.service.SysChatcontentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by try on 2017/8/27.
 */

@RestController
@RequestMapping(value = SystemChatContentAction.BASE_VIEW)
public class SystemChatContentAction {

    public static final String BASE_VIEW = "/chatContent";
    private static final Logger logger = LoggerFactory.getLogger(SystemChatContentAction.class);

    @Autowired
    @Qualifier("service.SysChatcontentService")
    private SysChatcontentService sysChatcontentService;

    /**
     * 聊天室列表
     *
     * @param page
     * @param query
     * @return
     */
    @RequestMapping(value = "/listChatcontent", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView listChatcontent(Page page, SysChatcontentQuery query) {
        logger.info("Call SysChatContentAction.listChatcontent({},{})", page.toString(), query.toString());
        List<SysChatcontentView> listChatcontent = sysChatcontentService.selectSysChatcontentListByPage( query,page);
        ModelAndView mv = new ModelAndView(BASE_VIEW + "/listChatcontent");
        mv.addObject("page", page); // 返回分页
        mv.addObject("query", query);// 查询条件
        mv.addObject("listChatcontent", listChatcontent); // 返回查询结果集
        return mv;
    }

    /**
     * 添加内容
     *
     * @param sysChatcontent
     * @param session
     * @return
     */
    @RequestMapping(value = "/addSysChatcontent", method = RequestMethod.POST)
    @SystemControllerLog(description = "添加内容")
    public int addSysChatcontent(SysChatcontent sysChatcontent, HttpSession session) {
        logger.info("Call SysChatContentAction.addSysChatcontent({})", sysChatcontent.toString());
        return sysChatcontentService.addSysChatcontent(sysChatcontent);

    }

    /**
     * 查询聊天内容
     * @param id
     * @return
     */
    @RequestMapping(value = "/viewSysChatcontent", method = RequestMethod.POST)
    public SysChatcontent viewSysChatcontent(String id) {
        logger.info("Call SysChatContentAction.viewSysChatcontent({})", id);
        return sysChatcontentService.selectSysChatcontentById(id);
    }

    /**
     *  更新聊天内容
     * @param sysChatcontent
     * @return
     */
    @RequestMapping(value = "/updateSysChatcontent", method = RequestMethod.POST)
    @SystemControllerLog(description = "更新聊天内容")
    public int updateSysChatcontent(SysChatcontent  sysChatcontent) {
        logger.info("Call SysChatContentAction.updateSysChatcontent({})", sysChatcontent.toString());
        return sysChatcontentService.updateSysChatcontent(sysChatcontent);
    }

    /**
     * 删除聊天内容
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteSysChatcontent", method = RequestMethod.POST)
    @SystemControllerLog(description = "删除聊天内容")
    public int deleteSysChatcontent(String id) {
        logger.info("Call SysChatContentAction.deleteSysChatcontent({})", id);
        return sysChatcontentService.deleteSysChatcontent(id);
    }
}
